<template>
  <div>
    <el-container>
      <el-header>
        <div class="logo">
          <img src="../assets/avatar.jpg" alt="" />
        </div>

        <p>后台管理系统</p>
        <div class="right">
          <img :src="userList.head_img | imgUrl" alt="" />
          <!-- <p>欢迎你:{{ userList.nickname }}</p> -->
          <el-dropdown @command="handleCommand">
            <span class="el-dropdown-link">
              欢迎你: {{ userList.nickname
              }}<i class="el-icon-arrow-down el-icon--right"></i>
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="a">首页</el-dropdown-item>
              <el-dropdown-item command="b">退出登录</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
          <!-- <el-button type="info">退出</el-button> -->
        </div>
      </el-header>
      <el-container>
        <el-aside :width="isCollapse ? '64px' : '200px'">
          <div class="toggle-button" @click="isCollapse = !isCollapse">
            <i :class="isCollapse ? 'el-icon-s-unfold' : 'el-icon-s-fold'"></i>
          </div>
          <!-- 左侧导航 -->
          <el-menu
            class="el-menu-vertical-demo"
            background-color="#545c64"
            text-color="#fff"
            active-text-color="#ffd04b"
            router
            unique-opened
            :collapse="isCollapse"
            :collapse-transition="false"
            center
          >
            <el-submenu index="1">
              <template slot="title">
                <i class="el-icon-location"></i>
                <span>文章管理</span>
              </template>

              <el-menu-item index="/home/postlist">
                <i class="el-icon-s-custom"></i>文章列表</el-menu-item
              >
              <el-menu-item index="/home/postpublish">
                <i class="el-icon-circle-plus"></i>发布文章</el-menu-item
              >
            </el-submenu>
            <el-submenu index="2">
              <template slot="title">
                <i class="el-icon-circle-plus"></i>
                <span>栏目管理</span>
              </template>

              <el-menu-item index="/home/category">
                <i class="el-icon-s-custom"></i>
                栏目列表</el-menu-item
              >
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import { userDetailByIdAPI } from "@/apis/user";
import { getUserId } from "@/utils/localDate";

export default {
  data() {
    return {
      userList: [],
      isCollapse: false,
    };
  },
  async created() {
    const { data: res } = await userDetailByIdAPI(getUserId());
    // console.log(res);
    this.userList = res.data;
    console.log(this.userList);
  },
  methods: {
    // 下拉事件触发
    handleCommand(command) {
      if (command == "b") {
        this.$router.push("/login");
      } else {
        this.$router.push("/home");
      }
    },
  },
};
</script>

<style lang="less" scoped>
.el-container {
  height: 100vw;
}
.el-dropdown-link {
  padding: 0 20px;
}
.el-header {
  background-color: #b3c0d1;
  color: #333;
  text-align: center;

  display: flex;
  justify-content: space-between;
  align-items: center;
  .logo {
    width: 60px;
    height: 60px;
    background-color: red;
    border-radius: 50%;
    overflow: hidden;
  }
  .right {
    display: flex;
    justify-content: center;
    align-items: center;
    img {
      width: 60px;
      height: 60px;
      background-color: red;
      border-radius: 50%;
      overflow: hidden;
    }
    p {
      padding: 0 20px;
    }
  }
}

.el-aside {
  background-color: #d3dce6;
  color: #333;
  text-align: center;

  .toggle-button {
    height: 50px;
    // background-color: red;
    color: red;
    font-size: 50px;
    text-align: left;
  }
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  // text-align: center;
}
.el-menu {
  border: 0;
}
</style>
